import { Injectable } from '@angular/core';
import { QRCode } from '../qrcode/qrcode/QRCode';
import { ErrorCorrectLevel } from '../qrcode/qrcode/ErrorCorrectLevel';
import { QRNumber } from '../qrcode/qrcode/QRNumber';
import { QRAlphaNum } from '../qrcode/qrcode/QRAlphaNum';
import { QR8BitByte } from '../qrcode/qrcode/QR8BitByte';
import { QRKanji } from '../qrcode/qrcode/QRKanji';
/*
  Generated class for the QrcodeProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class QrcodeProvider {

  constructor(
    public qrcode: QRCode) {
    console.log('Hello QrcodeProvider Provider');
  }

	/**
	 * 二维码生成器
	 */
  public makeQRcode(dom: any, url: any) {
    this.qrcode.setTypeNumber(10);
    this.qrcode.setErrorCorrectLevel(ErrorCorrectLevel.H);
    this.qrcode.clearData();
    this.qrcode.addData(url);
    this.qrcode.make();
    if (dom) {
      var img = document.createElement('img');
      img.setAttribute('src', this.qrcode.toDataURL());
      dom.nativeElement.innerHTML = "";
      dom.nativeElement.appendChild(img);
    }
  }
}